from convert import ConverterFactory
from generated_units import create_units_map, get_translations

from nose.tools import *

cf = None

def setup():
    global cf
    um = create_units_map()
    cf = ConverterFactory(um, get_translations(um))

def g2g_test():
    c = cf.get_converter("g", "g")
    assert c.convert(1) == 1

def g2dg_test():
    c = cf.get_converter("g", "dg")
    assert_almost_equal(c.convert(10), 100)

def tonne2g_test():
    c = cf.get_converter("tonne", "g")
    assert_almost_equal(c.convert(42), 42 * 1000 * 1000)

def has_finnish_test():
    assert cf.has_locale("fi_FI")

def finnish2finnish_test():
    c = cf.get_converter_localized("gramma", "kilogramma", "fi_FI")
    assert_almost_equal(c.convert(1000), 1)

def finnish2default_test():
    c = cf.get_converter_localized("gramma", "kg", "fi_FI")
    assert_almost_equal(c.convert(1000), 1)

def default2finnish_test():
    c = cf.get_converter_localized("g", "kilogramma", "fi_FI")
    assert_almost_equal(c.convert(1000), 1)
